<?php
//
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'work';
model('core/core')->checklogin();
$return['pluginset']['title']=$return['pluginset']['title']?:'群互推';
$id=intval($_RQ['id']);
$this->session('isgochat'.$id,1);
if($_RQ['op']=='work'){
	set_html('title','加入企业微信群');
	if($id){
		$item=pdo_get('jy_xiaoeknow_video',array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));
	}else{
		$item=$return['pluginset'];
	}
	$return['sharedata']=array(
			'title'=>'加入《'.$item['title'].'》-'.$return['pluginset']['title'],
			'desc'=>$return['pluginset']['share_desc']?$return['pluginset']['share_desc']:'微信群互推，用心链接客户！',
			'link'=>custom_url('jy_xiaoeknow/gochat/'.$_RQ['op'].'/id='.$id,true),
			'imgUrl'=>ATTACHMENT_URL.$return['pluginset']['share_image']
	);
	$addlog=pdo_get('jy_xiaoeknow_quan_log',array('uniacid'=>$_SESSION['uniacid'],'merchid'=>$_SESSION['onemerchid'],'mid'=>$_SESSION['uid'],'qun_id'=>$id));
	if($_RQ['fromqun']){
		if(!$addlog['id']){
			$data=array(
				'uniacid'=>$_SESSION['uniacid'],
				'mid'=>$_SESSION['uid'],
				'qun_id'=>$id,
				'isadd'=>1,
				'createtime'=>TIMESTAMP,
			);
			pdo_insert('jy_xiaoeknow_quan_log',$data);
		}else{
			pdo_update('jy_xiaoeknow_quan_log',array('isadd'=>1),array('uniacid'=>$_SESSION['uniacid'],'merchid'=>$_SESSION['onemerchid'],'mid'=>$_SESSION['uid'],'qun_id'=>$id));
		}
	}
	$return['item']=$item;
	if($addlog['id']){
		$return['errormsg']='您已加过本群，无需再加，您可以分享本群给朋友们！';
		exi($return);
	}elseif($_SESSION['openid']){
		if(!$item['ewmurl']){
			$return['errormsg']=$id?'该群未添加《群加入二维码链接地址》':'平台未添加《群加入二维码链接地址》';
			exi($return);
		}else{
			exi('','',$item['ewmurl']);
		}
	}else{
		$return['errormsg']='非微信环境下访问，不能直接加群，可以尝试扫码！';
		exi($return);
	}
}
if($_RQ['op']=='weixin'){
	set_html('title','添加微信群');
	$item=pdo_get('jy_xiaoeknow_video',array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));
	$return['sharedata']=array(
			'title'=>'添加微信群《'.$item['name'].'》-'.$return['pluginset']['title'],
			'desc'=>$return['pluginset']['share_desc']?$return['pluginset']['share_desc']:'企业微信SCRM，用心链接客户！',
			'link'=>custom_url('jy_xiaoeknow/gochat/'.$_RQ['op'].'/id='.$id,true),
			'imgUrl'=>ATTACHMENT_URL.$return['pluginset']['share_image']
	);
	$return['item']=$item;
	if($_SESSION['openid']){
		if(!$item['ewmurl']){
			$return['errormsg']='该群未添加《联系群二维码链接地址》';
			exi($return);
		}else{
			exi('','',$item['ewmurl']);
		}
	}else{
		$return['errormsg']='非微信环境下访问，不能直接添加群，可以尝试扫码！';
		exi($return);
	}
}
?>